<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<link type="text/css" href="css/news_all.css" rel="stylesheet" />
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="qury"
	value="&newstype=${newstype }&findtype=${ftype}&findkey=${fkey}" />
<c:set var="burl" value="?cpage=" />

 <c:if test="${newstype eq 1 }">
	<c:set var="newsdivision" value="뉴스"></c:set>
</c:if>
<c:if test="${newstype eq 2 }">
	<c:set var="newsdivision" value="인터뷰"></c:set>
</c:if>
<c:if test="${newstype eq 3 }">
	<c:set var="newsdivision" value="리뷰"></c:set>
</c:if> 

<div id="contents">
	<%@ include file="../tiles/newsmn.jspf"%>
	<div id="news" class="clearf">
		<ul>
			<c:if test="${newstype ne 4 }">
				<c:forEach var="nw" items="${newslist}">
					<li><div class="img">
							<p>
								<a href="news_v.bi?newsno=${nw.newsno}">${nw.newstit}${nw.newsno }</a>
							</p>
						</div></li>

					<c:set var="startbno" value="${startbno-1 }" />
				</c:forEach>
			</c:if>

		</ul>
	</div>


	<aside>
		<div class="sidenews">
		<h2>${newsdivision} 많이본 게시물</h2><hr/>
			<ul >
			<c:forEach var="p" begin="0" end="20" items="${count}">
					<li>${p.newstit}</li>
				</c:forEach>
			</ul>
		</div>
		
	</aside>

	<div id="search" class="clearf">
		<p>

			<c:if test="${cpage ne 1}">
				<a href="?${burl}1">처음</a>
			</c:if>
			<c:if test="${cpage ne 1 }">
				<a href="${burl}${cpage-1}${qury}" title="이전-1"> ◀ </a>
			</c:if>
			<c:if test="${cpage eq 1 }"> ◀ </c:if>
			<c:if test="${cpage ge 11 }">
				<a href="${burl}${cpage-10}${qury}" title="이전-10"> ◁◁ </a>
			</c:if>
			<c:if test="${cpage le 10 }"> ◁◁ </c:if>
			<%--페이지 네비게이션 출력 --%>
			<c:forEach var="p" begin="${startnav }" end="${startnav+9 }">
				<c:if test="${p le allpage }">
					<!-- 맨 마지막 페이지 까지만 출력 -->
					<c:if test="${cpage eq p }">
						<span class="cpage">${p}</span>
					</c:if>
					<c:if test="${cpage ne p}">
						<a href="${burl}${p}${qury}">${p}</a>
					</c:if>
				</c:if>
			</c:forEach>

			<c:if test="${cpage ne allpage and cpage+9 lt allpage}">
				<a href="${burl}${cpage+10}${qury}" title="이전+10"> ▷▷ </a>


			</c:if>
			<c:if test="${cpage ne allpage}">
				<a href="${burl}${cpage+1}${qury}" title="이전+1"> ▶ </a>
			</c:if>

			<c:if test="${cpage+9 gt allpage }">
			 ▷▷ 
		</c:if>
			<c:if test="${cpage eq allpage }"> ▶ </c:if>
			<c:if test="${cpage ne allpage }">
				<a href="${burl}${allpage}" title="마지막페이지로 이동">마지막</a>
			</c:if>
		</p>

		<select name="findtype"><option>선탁하세요</option>
			<option value="newstit">제목</option>
			<option value="newscontents">본문</option>
			<option value="wdate">작성일</option>
		</select> <input type="text" name="findkey" />
		<button type="button" id="findbtn">검색하기</button>

	</div>

</div>

<%-- 
<p>총 게시물수 : ${total }</p>
<p>페이지당 게시물수 : ${perpage }</p>
<p>총 페이지수 : ${allpage }</p>
<p>현재 페이지 : ${cpage }</p>
<p>nav시작번호 : ${startnav }</p>
<p>게시물 글 시작번호 : ${startbno }</p>
<p>검색어 대상 유형: ${ftype}</p>
<p>검색 값 : ${fkey }</p>
 --%>

<script type="text/javascript">
	var findbtn = document.getElementById("findbtn");
	findbtn.onclick = function() {

		var ftype = document.getElementsByName("findtype")[0].value;
		var fkey = document.getElementsByName("findkey")[0].value;
		var newstype = "${newstype}";
		var url = "";
		var find = "?newstype=" + newstype + "&findtype=" + ftype + "&findkey="
				+ fkey;
		//var find ="?findtype=" + ftype + "&findkey=" + fkey;
		location.href = url + find;

	};
</script>
